n, m = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(n)]

mainLand = set()


def dfs(i, j, isLand=False):
    if i < 0 or i >= n: return
    if j < 0 or j >= m: return
    if board[i][j] != 1 or (i, j) in mainLand:
        return
    if isLand:
        mainLand.add((i, j))
    if not isLand:
        board[i][j] = 0
    dfs(i + 1, j, isLand)
    dfs(i - 1, j, isLand)
    dfs(i, j + 1, isLand)
    dfs(i, j - 1, isLand)


for x in range(n):
    dfs(x, 0, True)
    dfs(x, m - 1, True)
for y in range(m):
    dfs(0, y, True)
    dfs(n - 1, y, True)

for x in range(n):
    for y in range(m):
        if board[x][y] == 1:
            dfs(x, y)

for i in range(n):
    for j in range(m):
        print(board[i][j], end=' ')
    print()
